package com.ruoyi.project.WebMoudle.advertSeat.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.WebMoudle.advertSeat.domain.AdvertSeat;
import com.ruoyi.project.WebMoudle.advertSeat.service.IAdvertSeatService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 店铺广告位Controller
 * 
 * @author ruoyi
 * @date 2020-07-01
 */
@Controller
@RequestMapping("/advertSeat/advertSeat")
public class AdvertSeatController extends BaseController
{
    private String prefix = "advertSeat/advertSeat";

    @Autowired
    private IAdvertSeatService advertSeatService;

    @RequiresPermissions("advertSeat:advertSeat:view")
    @GetMapping()
    public String advertSeat()
    {
        return prefix + "/advertSeat";
    }

    /**
     * 查询店铺广告位列表
     */
    @RequiresPermissions("advertSeat:advertSeat:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AdvertSeat advertSeat)
    {
        startPage();
        List<AdvertSeat> list = advertSeatService.selectAdvertSeatList(advertSeat);
        return getDataTable(list);
    }

    /**
     * 导出店铺广告位列表
     */
    @RequiresPermissions("advertSeat:advertSeat:export")
    @Log(title = "店铺广告位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AdvertSeat advertSeat)
    {
        List<AdvertSeat> list = advertSeatService.selectAdvertSeatList(advertSeat);
        ExcelUtil<AdvertSeat> util = new ExcelUtil<AdvertSeat>(AdvertSeat.class);
        return util.exportExcel(list, "advertSeat");
    }

    /**
     * 新增店铺广告位
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存店铺广告位
     */
    @RequiresPermissions("advertSeat:advertSeat:add")
    @Log(title = "店铺广告位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AdvertSeat advertSeat)
    {
        return toAjax(advertSeatService.insertAdvertSeat(advertSeat));
    }

    /**
     * 修改店铺广告位
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AdvertSeat advertSeat = advertSeatService.selectAdvertSeatById(id);
        mmap.put("advertSeat", advertSeat);
        return prefix + "/edit";
    }

    /**
     * 修改保存店铺广告位
     */
    @RequiresPermissions("advertSeat:advertSeat:edit")
    @Log(title = "店铺广告位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AdvertSeat advertSeat)
    {
        return toAjax(advertSeatService.updateAdvertSeat(advertSeat));
    }

    /**
     * 删除店铺广告位
     */
    @RequiresPermissions("advertSeat:advertSeat:remove")
    @Log(title = "店铺广告位", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(advertSeatService.deleteAdvertSeatByIds(ids));
    }

    /**
     * 广告位号是否重复
     */
    @PostMapping("/checkNumUnique")
    @ResponseBody
    public String checkNumUnique(AdvertSeat advertSeat)
    {
        return advertSeatService.checkNumUnique(advertSeat);
    }
}
